package com.ybg.service;

import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ybg.bean.SystemConfig;
import com.ybg.dao.SystemConfigDao;
import com.ybg.utils.SystemConfigUtil;

/**
 * 系统参数Service类
 * 
 * @author ningjh
 * @since  2016-08-12
 */

@Service
public class SystemConfigService extends AbstractService {
	@Autowired
	private SystemConfigDao systemConfigDao;
	
	@PostConstruct
	public void refreshSystemConfig() {
		// 定时刷新系统参数。当前任务执行成功后，等待3分钟再执行下一次任务。
		asyncUtil.scheduleWithFixedDelay(new Runnable() {
			@Override
			public void run() {
				List<SystemConfig> list = systemConfigDao.queryForList();
				
				if(list != null) {
					for(SystemConfig config : list) {
						SystemConfigUtil.put(config.getParamkey(), config.getParamvalue());
					}
				}
			}}, 0L, 3 * 60L, TimeUnit.SECONDS);
	}
}
